package cn.edu.scau.cmi.xiehaizhou.client;

import cn.edu.scau.cmi.xiehaizhou.abstractFactory.factory.PolicyProducer;
import cn.edu.scau.cmi.xiehaizhou.abstractFactory.domainAbstractClass.AutoInsurance;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class AbstractFactoryCilent extends Application{
	@Override
	public void start(Stage primaryStage)
	{
		primaryStage.setTitle("抽象工厂模式");
		
		//分三部分布局
		VBox pane1 = new VBox();
		HBox pane2 = new HBox();
		GridPane pane3 = new GridPane();
		
		pane1.setAlignment(Pos.CENTER);
		pane2.setAlignment(Pos.CENTER);
		pane3.setAlignment(Pos.CENTER);
		pane3.setVgap(40);
		pane3.setHgap(10);
		
		//右上角部分
		pane3.setPadding(new Insets(10,10,10,10));
		pane3.add(new Label("姓名："), 0, 0);
		pane3.add(new Label("谢海洲"), 1, 0);
		pane3.add(new Label("学号："), 2, 0);
		pane3.add(new Label("201627010222"), 3, 0);
		pane3.add(new Label("公司"), 0, 1);
		pane3.add(new Label("保险类型"), 0, 2);
		//选择公司的下拉选择框
		ComboBox<String> cbo = new ComboBox<String>();
		cbo.getItems().addAll("中国人寿保险","平安保险");
		pane3.add(cbo, 1, 1);
		//选择保险的下拉选择框
		ComboBox<String> cbo2 = new ComboBox<String>();
		cbo2.getItems().addAll("驾驶员身体受伤","汽车损坏","人员伤亡","多种事故");
		pane3.add(cbo2, 1, 2);
		Button btn = new Button("显示保险信息");
		pane3.add(btn, 1, 3);
		
		//照片部分
		Image image = new Image("file:E:\\Image\\Image1.jpg");
		ImageView imv = new ImageView(image);
		imv.setFitHeight(250);
		imv.setFitWidth(200);
		pane2.getChildren().addAll(imv, pane3);
		
		//文本域部分
		TextArea txt = new TextArea();
		txt.setEditable(false);
		pane1.getChildren().addAll(pane2, txt);
		
		//按钮事件
				btn.setOnAction(e ->
				{
					String company = cbo.getSelectionModel().getSelectedItem();
					String insurance = cbo2.getSelectionModel().getSelectedItem();
					PolicyProducer pp = PolicyProducer.getFactory(company);
					AutoInsurance aInsurance = null;
					switch (insurance) {
					case "驾驶员身体受伤": aInsurance = pp.getBodyInjur();
						break;
					case "汽车损坏": aInsurance = pp.getAutoDamage();
						break;
					case "人员伤亡": aInsurance = pp.getPersonInjur();
						break;
					case "多种事故": aInsurance = pp.getMultiAccidents();
						break;
					default:
						break;
					}
					txt.setText(aInsurance.getInsurInfo());
				}
						);
		
		Scene scene = new Scene(pane1, 700, 500);
		primaryStage.setScene(scene);
		primaryStage.show();
		
	}
	
	public static void main(String[] args)
	{
		Application.launch(args);
	}
}
